﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Evolution.Structure;
using Evolution.Structure.Globe;

namespace GameProject.ViewModel
{
    class WorldBuilderViewModel : ViewModelBase
    {
        private MainWindowViewModel mainWindowViewModel;

        public List<Nation> NationList
        {
            get
            {
                return GlobalVar.Encyclopdia.NationList;
            }
            set
            {
                GlobalVar.Encyclopdia.NationList = value;
                onPropertyChanged("NationList");
            }
        }
        public Nation SelectedNation
        {
            get
            {
                return _SelectedNation;
            }
            set
            {
                _SelectedNation = value;
                base.onPropertyChanged("SelectedNation");
            }
        }
        private Nation _SelectedNation;


        public WorldBuilderViewModel(MainWindowViewModel mainWindowVM)
        {
            SelectedNation = GlobalVar.Encyclopdia.NationList.First();
            mainWindowViewModel = mainWindowVM;
            IsMediumMapChosen = true;
            WaterLand = 50;
            Forest = 1;
            Mountain = 1;
            GrassLand = 1;
        }

        public ICommand OpenGameMenuCommand
        {
            get
            {
                if (_OpenGameMenuCommand == null)
                {
                    _OpenGameMenuCommand = new RelayCommand(param => mainWindowViewModel.OpenGameMenu(), null);
                }
                return _OpenGameMenuCommand;
            }
        }
        private ICommand _OpenGameMenuCommand;


        public ICommand OpenWorldCommand
        {
            get
            {
                if (_OpenWorldCommand == null)
                {
                    _OpenWorldCommand = new RelayCommand(param => openWorld(), null);
                }
                return _OpenWorldCommand;
            }
        }
        private ICommand _OpenWorldCommand;

        public bool IsSmallMapChosen { get; set; }
        public bool IsMediumMapChosen { get; set; }
        public bool IsLargeMapChosen { get; set; }

        public int WaterLand { get; set; }
        public int Forest { get; set; }
        public int Mountain { get; set; }
        public int GrassLand { get; set; }

        private void openWorld()
        {
            int worldSize=0;
            if (IsSmallMapChosen)
                worldSize = 30;
            if (IsMediumMapChosen)
                worldSize = 50;
            if (IsLargeMapChosen)
                worldSize = 80;

            // Setze Nation + Startgeld + StartTechnologien
            GlobalVar.CurrentPlayer.Nation = SelectedNation;
            Resource startMoney = new Resource(Evolution.Structure.Globe.ValueType.Absolute,SelectedNation.SeedMoney);
            GlobalVar.CurrentPlayer.Technologies.AddRange(GlobalVar.CurrentPlayer.Nation.StartingTechnologies);
            GlobalVar.CurrentPlayer.PlayerResources.MoneyPoints = startMoney;

            mainWindowViewModel.GenerateAndOpenWorld(worldSize, WaterLand, Forest, Mountain, GrassLand);
        }
    }
}
